package rabbitas.util.graphics {
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.display.Graphics;
	import rabbitas.util.IRabbitASUtil;

	/**
	 * @author martindyrby
	 */
	public class GraphicsUtil implements IRabbitASUtil {
		private var graphics : Graphics;
		private var isOpen : Boolean;
		
		public var target:Sprite;
		
		public function addChild(child:*) : void {
			var c:* = child;
			if(child is Fill) {
				if(isOpen) target.graphics.endFill();
				target.graphics.beginFill(c.color, c.alpha);
				isOpen = true;
			} else if(child is Rectangle) {
				target.graphics.drawRect(c.x, c.y, c.width, c.height);
			}
			
		}
		
		public function get value() : * {
			if(isOpen) target.graphics.endFill();
			return target.graphics;
		}
	}
}
